using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace zevenseas.Community.Web.UI.WebControls
{
    public class SPBoundUrlField : SPBoundField
    {
        protected override void ChildControlDataBinding(Control childControl, object dataItem, MemberDescriptor dataFieldPropertyDescriptor)
        {
            string propertyValueAsHtml = GetPropertyValueAsHtml(dataItem, dataFieldPropertyDescriptor.Name);
            SPFieldUrlValue GridUrlValue = new SPFieldUrlValue(propertyValueAsHtml);

            HyperLink GridUrlField = new HyperLink();

            GridUrlField.Text = GridUrlValue.Description;
            GridUrlField.NavigateUrl = GridUrlValue.Url;

            PlaceHolder placeHolder = (PlaceHolder)childControl;
            placeHolder.Controls.Add(GridUrlField);
        }

        protected override Control GetChildControlInstance()
        {
            return new PlaceHolder();
        }
    }
}